import Vue from 'vue'
import App from './App'
// 路由
import router from './router'
// elementUi
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import qs from 'qs';
import marked from "marked";
//图片预览插件
import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'

import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
//全局变量
import mate from './config/mate.js'


Vue.use(mavonEditor)
Vue.use(ElementUI);
Vue.prototype.mate = mate;

//Vue.use(Viewer) 默认配置写法
Vue.use(Viewer, {
	defaultOptions: {
		zIndex: 9999
	}
})

Vue.config.productionTip = false

var axios = require('axios')
axios.defaults.baseURL = mate.serverUrl
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=utf-8'

// 将API方法绑定到全局
Vue.prototype.$axios = axios
Vue.config.productionTip = false

Vue.prototype.$qs = qs;

Vue.prototype.$marked = marked;


/* eslint-disable no-new */
new Vue({
	el: '#app',
	router,
	components: {
		App
	},
	template: '<App/>'
})
// http response 拦截器

axios.interceptors.response.use(
	response => {
		return response;
	},
	error => {
		if (error.response) {
			if (error.response.status == 401) {
				store.commit(types.LOGOUT);
				router.replace({
					path: 'index',
					query: { redirect: router.currentRoute.fullPath }
				})
			}
		}
		return Promise.reject(error.response.data)  // 返回接口返回的错误信息
	}
);